#使用屏障实现线程同步
from random import randrange
from threading import Barrier,Thread
from time import sleep,ctime

num_runners=3
finish_line=Barrier(num_runners)
runners=['黎长读','陈彬彬','小菠萝']

def runner():
    name=runners.pop()
    sleep(randrange(2,5))
    print('%s 到达终点：%s\n'%(name,ctime()))
    finish_line.wait()

def main():
    threads=[]
    print('比赛开始！！！')
    for i in range(num_runners):
        threads.append(Thread(target=runner))
        threads[-1].start()
    for thread in threads:
        thread.join()
    print("比赛结束！")

if __name__=='__main__':
    main()